
#import "PUXuanCaiDetailsVC.h"
#import "PUPDLunBoView.h"
#import "UIButton+AxcButtonContentLayout.h"
#import "PUXuanCaiDetailsCell.h"
#import "PUMyAlbumDeleteView.h"
#import "PUReportVC.h"
#import "PUDTFBView.h"
#import "PUPhoneLogin.h"
@interface PUXuanCaiDetailsVC ()<UITableViewDelegate,UITableViewDataSource,FLMyAlbumDeleteViewDelegate,CPDTFBViewDelegate,FLSeeFlowerDetailsCellDelegate>
@property(nonatomic,strong)UITableView *tableView;
@property(nonatomic,strong)UIView* footerView;
@property(nonatomic,strong)PUPDLunBoView *lunBoView;//轮播图
@property(nonatomic,strong)UIView* bgView;
@property(nonatomic,strong)UIView* alphaView;
@property(nonatomic,strong)UILabel *countlab;
@property(nonatomic,strong)UILabel *dizhilab;
@property(nonatomic,strong)UILabel *lab1;
@property(nonatomic)int count;
@property(nonatomic,retain)NSString *username;
@property(nonatomic,retain)NSString *userphone;
@property(nonatomic,retain)NSString *userAddress;

@end

@implementation PUXuanCaiDetailsVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title=@"详情";
    self.view.backgroundColor=[UIColor whiteColor];
    self.count=1;
    
    if (self.isSelf!=1) {
        //右菜单栏目
        UIButton *rightbtn = [UIButton buttonWithType:UIButtonTypeCustom];
    //    rightbtn.frame = CGRectMake(self.view.bounds.size.width-20, 0, 20,20);
        rightbtn.frame = CGRectMake(self.view.bounds.size.width-40, 45, 30,30);
        [rightbtn setImage:[UIImage imageNamed:@"XL_more"] forState:UIControlStateNormal];
        [rightbtn setTitle:@" " forState:UIControlStateNormal];
        rightbtn.titleLabel.font = [UIFont systemFontOfSize: 14.0];
        [rightbtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [rightbtn addTarget:self action:@selector(buttonAction) forControlEvents:UIControlEventTouchUpInside];
        UIBarButtonItem *rightitem = [[UIBarButtonItem alloc] initWithCustomView:rightbtn];
        self.navigationItem.rightBarButtonItem=rightitem;
    }
  
    
    _tableView = [[UITableView alloc] init];
    _tableView.backgroundColor=[UIColor whiteColor];
    //解决scrollToRowAtIndexPath：滚动位置偏差问题
    _tableView.estimatedRowHeight = 0;
    _tableView.estimatedSectionFooterHeight = 0;
    _tableView.estimatedSectionHeaderHeight = 0;
    _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;//设置分隔线样式
    _tableView.bounces = YES;
    _tableView.delegate=self;
    _tableView.dataSource=self;
    [self.view addSubview:self.tableView];
    self.edgesForExtendedLayout = UIRectEdgeTop;
    _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;


    CGFloat h=55*KWidthScale;
    if(iPhoneXs){
        h=h+10;
    }
//    if (self.isSelf!=1) {
//        [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.top.equalTo(self.view.mas_top).offset(0);
//            make.left.equalTo(self.view.mas_left).offset(0);
//            make.right.equalTo(self.view.mas_right).offset(0);
//            make.bottom.equalTo(self.view.mas_bottom).offset(-95*KWidthScale);
//        }];
//    }else{
//        [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.top.equalTo(self.view.mas_top).offset(0);
//            make.left.equalTo(self.view.mas_left).offset(0);
//            make.right.equalTo(self.view.mas_right).offset(0);
//            make.bottom.equalTo(self.view.mas_bottom).offset(0);
//        }];
//    }
    
    [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view.mas_top).offset(0);
        make.left.equalTo(self.view.mas_left).offset(0);
        make.right.equalTo(self.view.mas_right).offset(0);
        make.bottom.equalTo(self.view.mas_bottom).offset(0);
    }];
   
    
    if (@available(iOS 15.0, *)) {
        //设置默认的分组头部间隙为0
        self.tableView.sectionHeaderTopPadding = CGFLOAT_MIN;
    }
    
//    UIButton *huoquBtn = [[UIButton alloc]init];
//    huoquBtn.clipsToBounds = YES;
//    huoquBtn.layer.cornerRadius =48*KWidthScale/2;
//    [huoquBtn addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside];
//    [huoquBtn setTitle:@"联系花友" forState:UIControlStateNormal];
//    huoquBtn.titleLabel.font = [UIFont systemFontOfSize: 18.0];
//    [huoquBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
//    [huoquBtn setBackgroundColor:[UIColor colorWithHex:0xFF729A]];
//    [self.view addSubview:huoquBtn];
//    
//    [huoquBtn mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.bottom.equalTo(self.view.mas_bottom).offset(-46*KWidthScale);
//        make.left.equalTo(self.view.mas_left).offset(16*KWidthScale);
//        make.right.equalTo(self.view.mas_right).offset(-16*KWidthScale);
//        make.height.equalTo(@(48*KWidthScale));
//    }];
//    
//    if (self.isSelf==1) {
//        huoquBtn.hidden=YES;
//    }
}
-(void)buttonAction{
//    CPMyAlbumDeleteView *v = [[CPMyAlbumDeleteView alloc]initCPPDMoreViewViewWith:[NSArray array] isJB:1];
//    v.delegate = self;
//    [v show];
    
    if ([Config getToken]==nil) {
        [self noLogin];
        return;
    }
    PUDTFBView *v1 = [[PUDTFBView alloc]initCPPDTHViewreportblack];
    v1.delegate = self;
    [v1 show];
}


-(void)CPMyAlbumDeleteViewdelectBtnClicked{
    PUReportVC *vc=[[PUReportVC alloc]init];
    vc.user_id=[self.model.userid intValue];
    vc.scene=2;
    [self.navigationController pushViewController:vc animated:YES];
}
-(void)CPPDTHViewreportblackSelectIndex:(int)index{
    int type=0;
    if(index==0){//举报
        type=1;
        
        PUReportVC *vc=[[PUReportVC alloc]init];
        vc.user_id=[self.model.userid intValue];
        vc.scene=2;
        [self.navigationController pushViewController:vc animated:YES];
    }
    if(index==1){//拉黑
        type=2;
//        [self showSVProgressHUDStr:@"拉黑"];
        
//        CPTipView *view =[[CPTipView alloc]initCPTipViewWithContent:@"加入黑名单后将不会收到对方发来的消息，可以在个人主页-黑名单中解除，是否拉黑" title:@"提示" confirmStr:@"确定" cancelStr:@"取消" buttonCount:2];
//            view.delegate=self;
//            [view show];
        
        NSMutableArray *data=[NSMutableArray array];
        //创建一个归档文件夹
        NSArray *library = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
        NSString *strLib = [[library objectAtIndex:0] stringByAppendingPathComponent:@"archive"];
        BOOL directory = YES;
        if (![[NSFileManager defaultManager] fileExistsAtPath:strLib isDirectory:&directory])
        {
            [[NSFileManager defaultManager] createDirectoryAtPath:strLib withIntermediateDirectories:NO attributes:nil error:nil];
        }
        //归档
        NSString *entityArchive = [strLib stringByAppendingPathComponent:[NSString stringWithFormat:@"lhDataArchive%@",[Config getID]]];
    //    [NSKeyedArchiver archiveRootObject:data toFile:entityArchive];
        //数据源从归档中读出
        NSMutableArray *array = [NSKeyedUnarchiver unarchiveObjectWithFile:entityArchive];
        NSLog(@"%@",array);
        if(array.count==0){
            array=[NSMutableArray array];
        }
        
        NSDictionary * d1 = @{
                              @"ID":self.model.flowers_ID,
                             };
        [array insertObject:d1 atIndex:0];
        [NSKeyedArchiver archiveRootObject:array toFile:entityArchive];
        NSMutableArray *array2 = [NSKeyedUnarchiver unarchiveObjectWithFile:entityArchive];
        NSLog(@"%@",array2);
        [[NSNotificationCenter defaultCenter] postNotificationName:@"CPBehaviorBlackNotification" object:self userInfo:@{@"flowers_ID":[NSString stringWithFormat:@"%@",self.model.flowers_ID]}];
        [self showSVProgressHUDStr:@"拉黑成功"];
        [self.navigationController popViewControllerAnimated:YES];
    }
}
-(void)btnClick{
   
}
//获取当前的时间
-(NSString*)getCurrentTimes{
     NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
     // ----------设置你想要的格式,hh与HH的区别:分别表示12小时制,24小时制
     [formatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
     //现在时间,你可以输出来看下是什么格式
     NSDate *datenow = [NSDate date];
     //----------将nsdate按formatter格式转成nsstring
     NSString *currentTimeString = [formatter stringFromDate:datenow];
     NSLog(@"currentTimeString =  %@",currentTimeString);
     return currentTimeString;
}
-(void)thbtnClick{
    
}
-(void)kfbtnClick{
    
}
-(void)lianxiBtnClick{
    
}
-(void)goumaibtnClick{
    
    if(self.bgView!=nil){
        if (self.userAddress==nil||[self.userAddress isEqualToString:@""]) {
            [self showSVProgressHUDStr:@"请填写收货地址"];
            return;
        }
        
        
        NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
        NSString *coin = [userDefaults objectForKey:[NSString stringWithFormat:@"coin_%@",[Config getID]]];
        if ([coin integerValue]<self.count*[self.model.flowers_JG integerValue]) {
            [self showSVProgressHUDStr:@"您的余额不足，请充值"];
//            CPXLRechargeVC *vc=[[CPXLRechargeVC alloc]init];
//            [self.navigationController pushViewController:vc animated:YES];
            return;
        }
        
        NSMutableArray *data=[NSMutableArray array];
        //创建一个归档文件夹
        NSArray *library = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
        NSString *strLib = [[library objectAtIndex:0] stringByAppendingPathComponent:@"archive"];
        BOOL directory = YES;
        if (![[NSFileManager defaultManager] fileExistsAtPath:strLib isDirectory:&directory])
        {
            [[NSFileManager defaultManager] createDirectoryAtPath:strLib withIntermediateDirectories:NO attributes:nil error:nil];
        }
        //归档
        NSString *entityArchive = [strLib stringByAppendingPathComponent:[NSString stringWithFormat:@"goumaiDataArchive%@",[Config getID]]];
    //    [NSKeyedArchiver archiveRootObject:data toFile:entityArchive];
        //数据源从归档中读出
        NSMutableArray *array = [NSKeyedUnarchiver unarchiveObjectWithFile:entityArchive];
        NSLog(@"%@",array);
        if(array.count==0){
            array=[NSMutableArray array];
        }
        
        NSDictionary * d1 = @{
                              @"username":[Config getnickname],
                              @"userimage":[Config getOriginal_avatar],
                              @"userAddress":self.userAddress,
                              @"flowers_name":self.model.flowers_name,
                              @"flowers_image":self.model.flowers_image,
                              @"flowers_JG":self.model.flowers_JG,
                              @"flowers_buyCount":[NSString stringWithFormat:@"%d",self.count],
                              @"flowers_buyTime":[self getCurrentTimes],
                             };
        [array insertObject:d1 atIndex:0];
        [NSKeyedArchiver archiveRootObject:array toFile:entityArchive];
        NSMutableArray *array2 = [NSKeyedUnarchiver unarchiveObjectWithFile:entityArchive];
        NSLog(@"%@",array2);
        [self showSVProgressHUDStr:@"购买成功"];
        [self bgViewTapGesture];
        
    }else{
        
        
        CGFloat h=55*KWidthScale;
        if(iPhoneXs){
            h=h+10;
        }
        self.bgView=[[UIView alloc]init];
        self.bgView.backgroundColor=[UIColor blackColor];
        self.bgView.alpha=0.6;
        self.bgView.frame=CGRectMake(0, 0, _window_width, _window_height-h);
        //    self.bgView.userInteractionEnabled=YES;
        //    UITapGestureRecognizer *bgViewTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(bgViewTapGesture)];
        //
        //    [self.bgView addGestureRecognizer:bgViewTap];
        //    [[UIApplication sharedApplication].delegate.window addSubview:self.bgView];
        [self.view addSubview:self.bgView];
        
        [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.view.mas_top).offset(0);
            make.left.equalTo(self.view.mas_left).offset(0);
            make.right.equalTo(self.view.mas_right).offset(0);
            make.bottom.equalTo(self.view.mas_bottom).offset(-h);
        }];
        
        self.alphaView=[[UIView alloc]init];
        self.alphaView.frame=CGRectMake(0, 0, _window_width, _window_height-h);
//        self.alphaView.userInteractionEnabled=YES;
//        UITapGestureRecognizer *bgViewTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(bgViewTapGesture)];
//        [self.alphaView addGestureRecognizer:bgViewTap];
        //    [[UIApplication sharedApplication].delegate.window addSubview:self.alphaView];
        [self.view addSubview:self.alphaView];
        [self.alphaView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.view.mas_top).offset(0);
            make.left.equalTo(self.view.mas_left).offset(0);
            make.right.equalTo(self.view.mas_right).offset(0);
            make.bottom.equalTo(self.view.mas_bottom).offset(-h);
        }];
        
        
        UIView *whiteview=[[UIView alloc]init];
        whiteview.backgroundColor=[UIColor whiteColor];
        [self.alphaView addSubview:whiteview];
        whiteview.frame=CGRectMake(0, self.view.frame.size.height-_window_width*0.608-h, _window_width, _window_width*0.608);
        //    [whiteview mas_makeConstraints:^(MASConstraintMaker *make) {
        ////        make.top.equalTo(self.alphaView.mas_bottom).offset(-_window_width*0.608);
        //        make.left.equalTo(self.view.mas_left).offset(0);
        //        make.right.equalTo(self.view.mas_right).offset(0);
        //        make.bottom.equalTo(self.view.mas_bottom).offset(0);
        //        make.height.equalTo(@(_window_width*0.608));
        //
        //    }];
        
        
        UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:whiteview.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(8*KWidthScale, 8*KWidthScale)];
        CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
        maskLayer.frame = whiteview.bounds;
        maskLayer.path = maskPath.CGPath;
        whiteview.layer.mask = maskLayer;
        
        UIImageView *img=[[UIImageView alloc]init];
        img.frame=CGRectMake(12*KWidthScale, 12*KWidthScale, 72*KWidthScale, 72*KWidthScale);
        img.layer.masksToBounds=YES;
        img.layer.cornerRadius = 4;
        [whiteview addSubview:img];
        img.image=[UIImage imageNamed:self.model.flowers_image[0]];
        
        UILabel *titleLab = [[UILabel alloc] init];
        titleLab.frame=CGRectMake(12*KWidthScale+img.frame.origin.x+img.frame.size.width,16*KWidthScale,_window_width-img.frame.size.width-12*KWidthScale*2, 18*KWidthScale);
        titleLab.text=self.model.flowers_name;
        titleLab.font=[UIFont boldSystemFontOfSize:19];
        titleLab.textColor = [UIColor blackColor];
        [whiteview addSubview:titleLab];
        
        UILabel *detailsLab = [[UILabel alloc] init];
        detailsLab.text=@"";
        detailsLab.font=[UIFont systemFontOfSize:20];
        detailsLab.textColor = [UIColor redColor];
        [whiteview addSubview:detailsLab];
        
        
        NSString *str=self.model.flowers_JG;
        NSString *app_icp=str;
        NSString *topStr=app_icp;
        NSString *s=[NSString stringWithFormat:@"%@",topStr];
        
        CGSize size2 = [s sizeWithAttributes:@{NSFontAttributeName: [UIFont boldSystemFontOfSize:24]}];
        CGFloat width2 = ceil(size2.width);
        detailsLab.frame=CGRectMake(12*KWidthScale+img.frame.origin.x+img.frame.size.width, titleLab.mj_y+titleLab.size.height+12*KWidthScale,width2, 34*KWidthScale);
        
        NSMutableAttributedString *hogan1 = [[NSMutableAttributedString alloc] initWithString:s];
        [hogan1 addAttribute:NSFontAttributeName value:[UIFont boldSystemFontOfSize:24] range:NSMakeRange(0, s.length)];
        [hogan1 addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithHex:0xFF729A] range:NSMakeRange(0, s.length)];
//        [hogan1 addAttribute:NSFontAttributeName value:[UIFont boldSystemFontOfSize:11] range:NSMakeRange(0, 1)];
//        [hogan1 addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithHex:0xFF729A] range:NSMakeRange(0,1)];
        detailsLab.attributedText = hogan1;
        
        UIImageView *JBImage=[[UIImageView alloc]init];
        JBImage.image=[UIImage imageNamed:@"充值金币"];
        [whiteview addSubview:JBImage];
        JBImage.frame=CGRectMake(detailsLab.mj_x+detailsLab.size.width+6*KWidthScale, titleLab.mj_y+titleLab.size.height+17*KWidthScale,24*KWidthScale, 24*KWidthScale);
        
        
        UILabel *signatureLab = [[UILabel alloc] init];
        signatureLab.font=[UIFont systemFontOfSize:13];
        signatureLab.textColor = [UIColor colorWithHex:0x888888];
        signatureLab.textAlignment=NSTextAlignmentRight;
        [whiteview addSubview:signatureLab];
        
        signatureLab.frame=CGRectMake(12*KWidthScale, titleLab.mj_y+titleLab.size.height+20*KWidthScale,whiteview.frame.size.width-12*KWidthScale*2, 18*KWidthScale);
        
        signatureLab.text=[NSString stringWithFormat:@"库存:%@",self.model.flowers_KC];
        
        
        UIButton *guanbiBtn=[[UIButton alloc]init];
        [guanbiBtn addTarget:self action:@selector(bgViewTapGesture) forControlEvents:UIControlEventTouchUpInside];
        [guanbiBtn setImage:[UIImage imageNamed:@"hua关闭"] forState:UIControlStateNormal];
        [whiteview addSubview:guanbiBtn];
        [guanbiBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(whiteview.mas_top).offset(12*KWidthScale);
            //        make.left.equalTo(view3.mas_left).offset(12*KWidthScale);
            make.right.equalTo(whiteview.mas_right).offset(-12*KWidthScale);
            //        make.bottom.equalTo(view3.mas_bottom).offset(0);
            make.width.equalTo(@(16*KWidthScale));
            make.height.equalTo(@(16*KWidthScale));
        }];
        
        
        UILabel *lab1 = [[UILabel alloc] init];
        lab1.text=@"收货地址";
        lab1.font=[UIFont boldSystemFontOfSize:15];
        lab1.textColor = [UIColor blackColor];
        //       self.titleLab.backgroundColor = [UIColor redColor];
        lab1.frame=CGRectMake(12*KWidthScale, img.frame.origin.y+img.frame.size.height+24*KWidthScale, 100, 20*KWidthScale);
        [whiteview addSubview:lab1];
        
        self.lab1=lab1;
        
        self.dizhilab = [[UILabel alloc] init];
        self.dizhilab.font=[UIFont systemFontOfSize:14];
        self.dizhilab.textColor = [UIColor colorWithHex:0x888888];
        self.dizhilab.numberOfLines=0;
        //    self.dizhilab.backgroundColor = [UIColor redColor];
        [whiteview addSubview:self.dizhilab];
        self.dizhilab.text=@"请选择收货地址 >";
        if (self.userAddress!=nil&&![self.userAddress isEqualToString:@""]) {
            self.dizhilab.text=self.userAddress;
        }
        self.dizhilab.frame=CGRectMake(12*KWidthScale, lab1.frame.origin.y+lab1.frame.size.height+12*KWidthScale, _window_width-24*KWidthScale, 30*KWidthScale);
        
        self.dizhilab.userInteractionEnabled=YES;
        UITapGestureRecognizer *dizhilabTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dizhilabTapGesture)];
        
        [self.dizhilab addGestureRecognizer:dizhilabTap];
        
        
        UIView *view4=[[UIView alloc]init];
        view4.backgroundColor=[UIColor whiteColor];
        [whiteview addSubview:view4];
        [view4 mas_makeConstraints:^(MASConstraintMaker *make) {
            //        make.top.equalTo(view3.mas_bottom).offset(12*KWidthScale);
            make.left.equalTo(whiteview.mas_left).offset(0);
            make.right.equalTo(whiteview.mas_right).offset(0);
            make.bottom.equalTo(whiteview.mas_bottom).offset(-12*KWidthScale);
            make.height.equalTo(@(48*KWidthScale));
        }];
        
        UILabel *lab4 = [[UILabel alloc] init];
        lab4.font=[UIFont systemFontOfSize:15];
        lab4.textColor = [UIColor blackColor];
        lab4.text=@"数量";
        [view4 addSubview:lab4];
        
        [lab4 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(view4.mas_top).offset(0);
            make.left.equalTo(view4.mas_left).offset(12*KWidthScale);
            make.right.equalTo(view4.mas_right).offset(0);
            make.bottom.equalTo(view4.mas_bottom).offset(0);
            //        make.height.equalTo(@(48*KWidthScale));
        }];
        
        UIButton *btnjia=[[UIButton alloc]init];
        [btnjia addTarget:self action:@selector(btnjiaClick) forControlEvents:UIControlEventTouchUpInside];
        [btnjia setImage:[UIImage imageNamed:@"huajia"] forState:UIControlStateNormal];
        [view4 addSubview:btnjia];
        [btnjia mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(view4.mas_top).offset(16*KWidthScale);
            //        make.left.equalTo(view3.mas_left).offset(12*KWidthScale);
            make.right.equalTo(view4.mas_right).offset(-12*KWidthScale);
            //        make.bottom.equalTo(view3.mas_bottom).offset(0);
            make.width.equalTo(@(16*KWidthScale));
            make.height.equalTo(@(16*KWidthScale));
        }];
        
        
        UIButton *btnjian=[[UIButton alloc]init];
        [btnjian addTarget:self action:@selector(btnjianClick) forControlEvents:UIControlEventTouchUpInside];
        [btnjian setImage:[UIImage imageNamed:@"huajian"] forState:UIControlStateNormal];
        [view4 addSubview:btnjian];
        [btnjian mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(view4.mas_top).offset(16*KWidthScale);
            //        make.left.equalTo(view3.mas_left).offset(12*KWidthScale);
            make.right.equalTo(view4.mas_right).offset(-100*KWidthScale);
            //        make.bottom.equalTo(view3.mas_bottom).offset(0);
            make.width.equalTo(@(16*KWidthScale));
            make.height.equalTo(@(16*KWidthScale));
        }];
        
        self.countlab = [[UILabel alloc] init];
        self.countlab.font=[UIFont systemFontOfSize:15];
        self.countlab.textColor = [UIColor blackColor];
        self.countlab.text=[NSString stringWithFormat:@"%d",self.count];
        self.countlab.textAlignment=NSTextAlignmentCenter;
        self.countlab.backgroundColor=[UIColor colorWithHex:0xF3F3F3];
        self.countlab.layer.masksToBounds=YES;
        self.countlab.layer.cornerRadius = 4;
        [view4 addSubview:self.countlab];
        [self.countlab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(view4.mas_top).offset(12*KWidthScale);
            //        make.left.equalTo(view3.mas_left).offset(12*KWidthScale);
            make.right.equalTo(view4.mas_right).offset(-40*KWidthScale);
            //        make.bottom.equalTo(view3.mas_bottom).offset(0);
            make.width.equalTo(@(48*KWidthScale));
            make.height.equalTo(@(24*KWidthScale));
        }];
    }
}
-(void)bgViewTapGesture{
    [self.bgView removeFromSuperview];
    self.bgView=nil;
    
    [self.alphaView removeFromSuperview];
    self.alphaView=nil;
    
}
-(void)btnjiaClick{
    if(self.count==[self.model.flowers_KC intValue]){
        [self showSVProgressHUDStr:@"购买数量不能超过库存数量"];
        return;
    }
    self.count=self.count+1;
    self.countlab.text=[NSString stringWithFormat:@"%d",self.count];
}
-(void)btnjianClick{
    if (self.count==1) {
        return;
    }
    self.count=self.count-1;
    self.countlab.text=[NSString stringWithFormat:@"%d",self.count];
}

-(void)dizhilabTapGesture{
   
}
-(void)showuserAddress:(NSString *)userAddress{
    NSString *str=userAddress;
    self.dizhilab.text=str;
    //设置行距，并根据文本计算高度
    ////// ////// ////// ////// ////// //////
    //富文本属性
    NSMutableDictionary *textDict = [NSMutableDictionary dictionary];
    //基本属性设置
    //字体颜色
    textDict[NSForegroundColorAttributeName] = [UIColor colorWithHex:0x888888];
    //字号大小
    textDict[NSFontAttributeName] = [UIFont systemFontOfSize:14.0];
    //段落样式
    NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc] init];
    //行间距
    paraStyle.lineSpacing = 3.0;
    //首行文本缩进
//  paraStyle.firstLineHeadIndent = 20.0;
    //使用
    //文本段落样式
    textDict[NSParagraphStyleAttributeName] = paraStyle;
    //赋值
    self.dizhilab.attributedText = [[NSAttributedString alloc] initWithString:str attributes:textDict];
    
    CGFloat size2 = [self getSpaceLabelHeight:str withAttrDict:textDict withWidth:_window_width-24*KWidthScale];
    
    
    self.dizhilab.frame=CGRectMake(12*KWidthScale, self.lab1.frame.origin.y+self.lab1.frame.size.height+6*KWidthScale, _window_width-24*KWidthScale, size2);
}
//计算有行距的文本的文本高度
-(CGFloat)getSpaceLabelHeight:(NSString *)str withAttrDict:(NSMutableDictionary *)dict withWidth:(CGFloat)width {
    CGSize size = [str boundingRectWithSize:CGSizeMake(width, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:dict context:nil].size;
    return size.height;
}

-(void)showSVProgressHUDStr:(NSString *)str{
    if ([str isKindOfClass:[NSNull class]]||str==nil||[str isEqualToString:@""]) {
        return;
    }
    [SVProgressHUD setDefaultStyle:SVProgressHUDStyleDark];
    [SVProgressHUD showImage:[UIImage imageNamed:@""] status:str];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:NO];
}

- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    
    NSArray *a=self.navigationController.viewControllers;
    if (a.count>1&&[a objectAtIndex:a.count-2]==self) {
        NSLog(@"push");
    }else if([a indexOfObject:self]==NSNotFound){
        NSLog(@"pop");
        [self.lunBoView removeTimer];
    }
}

- (PUPDLunBoView *)lunBoView {
    if (!_lunBoView) {
        _lunBoView = [[PUPDLunBoView alloc]init];
        _lunBoView.ispng=1;
//        _lunBoView.isSJEnter=self.isSJEnter;
        _lunBoView.isSJEnter=0;
//        _lunBoView.frame=CGRectMake(0, 0, _window_width, 100);
//        _lunBoView.isSelf=self.isSelf;
//        _lunBoView.delegate=self;
//        myview.frame=CGRectMake(0, 0, kScreenW, kScreenW);
//        _myview.backgroundColor = [UIColor blueColor];
//           [_myview reload:@[@"test",@"test",@"test"]];
    }
    return _lunBoView;
}

-(UIView *)footerView{
    if (!_footerView) {
        _footerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, _window_width, _window_width)];
        _footerView.backgroundColor = [UIColor colorWithHex:0xF3F3F3];
        _footerView.backgroundColor = [UIColor whiteColor];
        
        [_footerView addSubview:self.lunBoView];
        NSMutableArray *array=[NSMutableArray array];
        for (NSString *s in self.model.flowers_image) {
//            NSString *str=[NSString stringWithFormat:@"https://ddot.hongyi.chat/xl/flower/guanhua/%@.png",s];
            NSString *str=s;
            [array addObject:str];
        }
        [self.lunBoView reload:array];
        
        UIView *v=[[UIView alloc]init];
        v.frame=CGRectMake(0,_footerView.frame.size.height-20*KWidthScale,_window_width, 20*KWidthScale);
        v.backgroundColor=[UIColor whiteColor];
        [_footerView addSubview:v];
        
        UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:v.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(8*KWidthScale, 8*KWidthScale)];
        CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
        maskLayer.frame = v.bounds;
        maskLayer.path = maskPath.CGPath;
        v.layer.mask = maskLayer;

    }
    return _footerView;
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    /*
     contentInset 这个属性理解起来，很容易，但是，表述起来有点困难。
     直接说效果：就跟，css中padding属性作用是一样的。
     scrollView.contentInset = UIEdgeInsetsMake(50, 0, 0, 0);
     这样定义后，内容视图开始显示的坐标为（0，51）。
     */
    if (scrollView == _tableView) {
        CGFloat sectionHeaderHeight = _window_width;
        if (scrollView.contentOffset.y <= sectionHeaderHeight && scrollView.contentOffset.y >= 0) {
            scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);
        } else if (scrollView.contentOffset.y >= sectionHeaderHeight) {
            scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0);
        }
    }
    return;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return _window_width;
}
- (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return self.footerView;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
//    return 88*KWidthScale;//55
    //动态获取自定义cell的高度
    PUXuanCaiDetailsCell *cell = (PUXuanCaiDetailsCell*)[self tableView:tableView cellForRowAtIndexPath:indexPath];
    return cell.rowHeight;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
   
    static NSString *cellIdentifier1 = @"FLSeeFlowerDetailsCell";//定义一个可重用标识
    PUXuanCaiDetailsCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier1];//从重用队列里获取可重用的cell
    if (cell==nil)
    {
        //如果不存在，创建一个可重用cell
        cell =[[PUXuanCaiDetailsCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier1] ;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    
//    cell.backgroundColor=[UIColor blueColor];
//    cell.model=self.model;
    [cell setmodel:self.model isSelf:self.isSelf];
    cell.qgBtn.tag=indexPath.row;
    [cell.qgBtn addTarget:self action:@selector(qgBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    cell.delegate=self;
    return cell;
   
}

-(void)noLogin{
    PUPhoneLogin *vc=[[PUPhoneLogin alloc]init];
    UINavigationController *navVc = [[UINavigationController alloc] initWithRootViewController:vc];
    navVc.modalPresentationStyle=0;
    [self presentViewController:navVc animated:NO completion:nil];
}

-(void)qgBtnAction:(UIButton *)button{
    NSInteger index = button.tag;
    NSLog(@"%ld",(long)index);
    PUModel *model=self.model;
   
}
@end
